package cn.jdbc.TestFu.practicle;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class Test02 {
    public static void main(String[] args)throws Exception {
        Class<?> aClass = Class.forName("cn.jdbc.TestFu.practicle.CoreService");
        Object coreservice = aClass.newInstance();
        Field[] files = aClass.getDeclaredFields();
        for(Field field:files) {
            Class<?> type = field.getType();
            Object o = type.newInstance();
            field.setAccessible(true);
            field.set(coreservice, o);
        }
            Method say = aClass.getMethod("say");
            say.invoke(coreservice);
    }
}
class CoreService {
    private AdminService adminService;
  private CustomerService customerService;
    private OrderService orderService;
    private UserService userService;

    public void say() {
        adminService.say();
       customerService.say();
        orderService.say();
        userService.say();
    }
}
class AdminService {
    public void say() {
        System.out.println("say in AdminService!");
    }
}
class CustomerService {
    public void say() {
        System.out.println("say in CustomerService!");
    }
}
class OrderService {
    public void say() {
        System.out.println("say in OrderService!");
    }
}
class UserService {
    public void say() {
        System.out.println("say in UserService!");
    }
}
